package de.haw.adt.implementation;

import static de.haw.adt.implementation.Values.KILO;
import de.haw.adt.interfaces.IPower;

class Power extends AbstractPhysicalScalar implements IPower {

	private final double power;

	private Power(double power) {
		this.power = power;
	}
	
	@Override
	double getValue() {
		return power;
	}

	public int compareTo(IPower power) {
		return Double.compare(this.power, power.getW());
	}

	@Override
	public boolean equals(Object o) {
		if (o == this)
			return true;
		if (!(o instanceof IPower))
			return false;
		return this.compareTo((IPower) o) == 0;
	}

	public double getW() {
		return power;
	}

	public double getKW() {
		return power / KILO;
	}

	public IPower add(IPower power) {
		return valueOf(this.power + power.getW());
	}

	public IPower sub(IPower power) {
		return valueOf(this.power - power.getW());
	}	
	
	public static IPower valueOf(double power) {
		return new Power(power);
	}
}
